package com.wulinbus.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fancy.common.utils.StringUtil;
import com.wulinbus.model.RenderBannerModel;
import com.wulinbus.model.RenderProviderModel;
import com.wulinbus.service.RenderBannerService;
import com.wulinbus.service.RenderService;
import com.wulinbus.utils.CasUtil;

@Controller
public class RenderController {
	@Resource
	private RenderService renderService;
	@Resource
	private RenderBannerService renderBannerService;
	
	@RequestMapping("/render_index.html")
	public String render_index(Model model, HttpServletRequest request) {
		String uid = CasUtil.getUid(request);
		List<RenderProviderModel> renderProviderList = renderService.getRenderProviderAll();
		RenderBannerModel renderBannerModel=renderBannerService.getOne();
		model.addAttribute("renderBannerModel", renderBannerModel);
		model.addAttribute("renderProviderList", renderProviderList);
		model.addAttribute("uid", uid);
		return "page-render-index";
	}

	/**
	 * 渲染提供商详情
	 */
	@RequestMapping("/render_provider_detail.html")
	public String render_provider_detail(Integer rpid, Model model, HttpServletRequest request) {
		String uid = CasUtil.getUid(request);
		RenderProviderModel renderProviderModel = renderService.getRenderProviderModel(rpid);
		model.addAttribute("renderProviderModel", renderProviderModel);
		model.addAttribute("uid", uid);
		return "page-render-provider-detail";
	}

	/**
	 * 渲染提供商对比
	 */
	@RequestMapping("/render_compare.html")
	public String render_provider_compare(String rpids, Model model, HttpServletRequest request) {
		if (StringUtil.isEmpty(rpids)) {
			return "redirect:render_index.html";
		} else {
			String rpid[] = rpids.split(",");
			String uid = CasUtil.getUid(request);
			List<Integer> rpidList = new ArrayList<Integer>();
			if (rpid.length > 0) {
				for (String rpid_Str : rpid) {
					Integer rpid_Int = Integer.parseInt(rpid_Str);
					rpidList.add(rpid_Int);
				}
			}
			List<RenderProviderModel> renderProviderList = renderService.getRenderProviderArray(rpidList);
			model.addAttribute("renderProviderList", renderProviderList);
			model.addAttribute("uid", uid);
			return "page-render-compare";
		}
	}
}
